<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Promise构造函数</title>
    <script src="js/traceur.js"></script>
    <script src="js/bootstrap.js"></script>
    <script type="module">
        var promise = new Promise(function (resolve, reject) {
            var request = new XMLHttpRequest();
            var url = "data.json";
            request.open("GET", url);
            request.addEventListener("load", function () {
                if (request.status === 200) {
                    resolve(request.responseText);
                } else {
                    reject("Server Error:" + request.status);
                }
            }, false);
            request.addEventListener("error", function () {
                reject("Cannot Make Ajax Request");
            });
            request.send();
        });

        //履行价值
        var a = new Promise(function (resolve, reject) {
            var b = new Promise(function (res, rej) {
                rej("Reason");
            });
            resolve(b);
        });
        var c = new Promise(function (resolve, reject) {
            var d = new Promise(function (res, rej) {
                res("Result");
            });
            resolve(d);
        });
    </script>
</head>
<body>

</body>
</html>